package main

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/plugins/cors"
	"public_security/filter"
	"public_security/initial"
	_ "public_security/routers"
)

func main() {
	if beego.AppConfig.String("Mode") == "web" {
		beego.SetStaticPath("/", "static/web/html")
		beego.SetStaticPath("/js", "static/web/js")
		beego.SetStaticPath("/images", "static/web/images")
		beego.SetStaticPath("/libs", "static/web/libs")
		beego.SetStaticPath("/styles", "static/web/styles")
		beego.SetStaticPath("/html", "static/web/html")
	} else {
		beego.SetStaticPath("/", "static")
		beego.SetStaticPath("/static/js", "static/static/js")
		beego.SetStaticPath("/static/css", "static/static/css")
		beego.SetStaticPath("/static/fonts", "static/static/fonts")
		beego.SetStaticPath("/static/images", "static/static/images")
		beego.SetStaticPath("/static/img", "static/static/img")
		beego.SetStaticPath("/static/style", "static/static/style")
		beego.SetStaticPath("/static/tinymce", "static/static/tinymce/")
		beego.SetStaticPath("/static/ueditor", "static/static/ueditor")
		beego.SetStaticPath("/static/upload", "static/static/upload")
	}
	if beego.BConfig.RunMode == "dev" {
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
	}
	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowAllOrigins:  true,
		AllowMethods:     []string{"GET", "DELETE", "PUT", "PATCH", "POST"},
		AllowCredentials: true,
		AllowHeaders:     []string{"x-requested-with", "content-type"},
	}))
	beego.InsertFilter("/v1/*", beego.BeforeRouter, filter.UserFilterFunc)

	beego.Run()
	initial.Close()
}
